package org.wattdepot.cli.command;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the TotalPowerCommand class.
 * 
 * @author Yichi Xu
 *
 */
public class TestTotalPowerCommand extends CommandTestBed {
  
  @Test
  @Override
  public void testDoCommand() {
    String command;
    String result;
    
    TotalPowerCommand totalPowerCommand = new TotalPowerCommand(this.client);
    
    //Sad tests
    //Correct input "totalpower SIM_IPP 2009-10-26T18:15:00-10:00 fueltype waste"
    command = "totalpower foo 2009-10-26T18:15:00-10:00 fueltype waste";
    result = totalPowerCommand.doCommand(command);
    assertTrue("Checking that the source is invalid.", 
        result.startsWith(WattDepotCliCommand.SOURCE_ERROR));
    command = "totalpower SIM_IPP foo fueltype waste";
    result = totalPowerCommand.doCommand(command);
    assertTrue("Checking that the timestamp result is invalid.",
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
    
    
    //Happy tests
    command = "totalpower SIM_IPP 2009-10-26T18:15:00-10:00 fueltype waste";
    result = totalPowerCommand.doCommand(command);
    assertTrue("Checking that there is a result for the query",
        Double.valueOf(result) >= 0);
    assertFalse("Checking that the command is valid.",
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that the connection is fine.",
        result.equals(WattDepotCliCommand.CONNECTION_ERROR));
    assertFalse("Checking that the source is valid.",
        result.startsWith(WattDepotCliCommand.SOURCE_ERROR));
    assertFalse("Checking that the timestamp is valid.",
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
  }
}
